package com.example.javaeekeshe.mapper;

import com.example.javaeekeshe.pojo.OrderBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OrderMapper {
    @Insert("INSERT INTO `order` VALUES (null,#{uid},#{gid},#{ostate},#{otime},#{oaddress},#{omoney},#{oname},#{ophone},#{ocolor})")
    public void addOrder(OrderBean orderBean);

    @Select("SELECT * FROM `order` where uid  = #{uid} ORDER BY otime desc limit #{start},5")
    public List<OrderBean> getOrderByUid(Integer uid,Integer start);

    @Select("select * from `order` ORDER BY ostate limit #{start},5")
    public List<OrderBean> getAllOrder(Integer start);

    @Update("UPDATE `order` SET ostate = 1 where id=#{id}")
    public void send(Integer id);

    @Select(" select COUNT(*) from `order`")
    public Integer rowsAll();

    @Select(" select COUNT(*) from `order` WHERE uid =#{id}")
    public Integer rowsUid(Integer id);

    @Insert("UPDATE `order` SET ostate = 2 WHERE id = #{id}")
    public void receipt(Integer id);

}
